package com.newland.mesdk.demo.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.newland.mesdk.demo.main.R;
import com.newland.mesdk.demo.interfaceimpl.BuzzerInterfaceImpl;
import com.newland.mesdk.demo.main.MainActivity;
import com.newland.mesdk.demo.util.Const.MessageTag;

/**
 * Created by YJF 蜂鸣器模块
 */
public class BuzzerFragment extends Fragment implements OnClickListener {
	private MainActivity mainActivity;
	private BuzzerInterfaceImpl buzzerInterfaceImpl;
	private Button btnCall;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_buzzer, null);
		mainActivity = (MainActivity) getActivity();
		btnCall = (Button) view.findViewById(R.id.btn_buzzer_call);
		btnCall.setOnClickListener(this);
		return view;
	}

	@Override
	public void onClick(View v) {
		if (mainActivity.isDeviceInit()) {
			switch (v.getId()) {
			case R.id.btn_buzzer_call:
				if (mainActivity.processingisLocked()) {
					mainActivity
							.showMessage("请先完成或撤销当前操作...", MessageTag.ERROR);
				} else {
					mainActivity.connectDevice();
					buzzerInterfaceImpl = new BuzzerInterfaceImpl();
					mainActivity.processingLock();
					buzzerInterfaceImpl.call(3, 0, 500, 500);
					mainActivity.showMessage("操作蜂鸣器成功！" + "\r\n",
							MessageTag.NORMAL);
					mainActivity.processingUnLock();
				}
				break;
			}
		} else {
			mainActivity.showMessage("设备未初始化，请先初始化！" + "\r\n",
					MessageTag.NORMAL);
		}

	}

}
